package com.mdz.nc.Controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.mdz.nc.Entity.Sbxxb;
import com.mdz.nc.Entity.Ygxxb;
import com.mdz.nc.Mapper.YgxxbMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 孟德志
 * @since 2020-06-09
 */
@Controller
@RequestMapping("/nc/ygxxb")
public class YgxxbController {
    @Autowired
    private YgxxbMapper ygxxbMapper;
    @ResponseBody
    @RequestMapping(value = "/getygxx/{bmid}",method = RequestMethod.GET)
    public List<Ygxxb> getsbwh(@PathVariable("bmid") Integer bmid){
        List<Ygxxb> ygxxbs=ygxxbMapper.selectList(new QueryWrapper<Ygxxb>().eq("bmid",bmid));
        return ygxxbs;
    }

    @ResponseBody
    @RequestMapping(value = "/getzjm/{zjm}",method = RequestMethod.GET)
    public String getsbwh(@PathVariable("zjm") String zjm){
        return ygxxbMapper.getzjm(zjm);
    }

    @ResponseBody
    @RequestMapping(value = "/insertyg", method = RequestMethod.POST)
    public int insertyg(Ygxxb ygxxb) {
        String zjm = ygxxbMapper.getzjm(ygxxb.getXingm());
        ygxxb.setZjm(zjm);
        return ygxxbMapper.insert(ygxxb);
    }

    @ResponseBody
    @RequestMapping(value = "/getbmidbyshiyr/{shiyr}", method = RequestMethod.GET)
    public Integer getbmidbyshiyr(@PathVariable("shiyr") String shiyr){
        List<Ygxxb> ygxxbs= null;
        try {
            ygxxbs = ygxxbMapper.selectList(new QueryWrapper<Ygxxb>().eq("xingm",shiyr));
            return ygxxbs.get(0).getBmid();
        } catch (Exception e) {
            System.out.println("数据中查无此人");
            return 0;
        }
    }

    @ResponseBody
    @RequestMapping(value = "/getygid/{xingm}", method = RequestMethod.GET)
    public Integer getygid(@PathVariable("xingm") String xingm) {
        List<Ygxxb> ygxxbs = ygxxbMapper.selectList(new QueryWrapper<Ygxxb>().eq("xingm",xingm));
        return ygxxbs.get(0).getId();
    }

    @ResponseBody
    @RequestMapping(value = "/updateygxxb/{xingm}", method = RequestMethod.PUT)
    public Integer updatesbxxb(Ygxxb ygxxb, @PathVariable("xingm") String xingm) {
        return ygxxbMapper.update(ygxxb, new UpdateWrapper<Ygxxb>().eq("xingm", ygxxb.getXingm()));
    }
}

